<template>
  <PageTemplate :tableRequest="tableRequest" :metaDataRequestParams="metaDataRequestParams"
                :toolButtonList="toolButtonList" :multiDateConditionFormatType="1"
                @onMetaDataChange="handleMetaDataChange" @onToolClick="handleToolClick"
                @onRowClick="handleRowClick">
  </PageTemplate>
</template>
<script>
import PageTemplate from '@/components/page-template';
import { deleteTraceWorkflows } from '../api';
import { getParams } from '@/utils';
import mixin from './mixin';
import * as Fiber from 'fiber';

const urlParamObj = getParams(window.location.search);
export default {
  name: 'PageCancelDownList',
  mixins: [mixin],
  components: { PageTemplate },
  data() {
    return {
      tableRequest: {
        url: '/ajax.do?method=ajaxAction&managerName=traceWorkflowManager',
        managerMethod: 'getColPageInfo',
        otherArgs: { app: "1", "govdocType": "", "listType": "", "recordType": "stepBackRecord", paramTemplateIds: urlParamObj.textfield || '' }
      },
      metaDataRequestParams: {
        "key": "LIST_REPEAL_RECORD",
        "platform": 0,
      },
      toolButtonList: [],
    };
  },
  methods: {
    //按钮点击事件
    handleToolClick(buttonId, { selectedRows }, resetTableData) {
      switch (buttonId) {
        case 'delete':
          this.deleteSupervise(selectedRows, resetTableData);
          break;
      }
    },
    handleMetaDataChange({ globalParam }) {
      const needButtonList = ['delete'];
      this.initToolButtonList(needButtonList, globalParam);
    },
    deleteSupervise(selectedRows, resetTableData) {
      if (selectedRows.length < 1) {
        Fiber.message.warning(this.$i18n("MainLang.system_phrase"));
        return false;
      }
      $.confirm({
        'msg': this.$i18n("form.formmasterdatalist.suretodel"),
        ok_fn: function () {
          const ids = selectedRows.map(row => row.id).join(',');
          const args = {
            ids,
            app: '1'
          };
          const params = `managerMethod=deleteTraceWorkflows&arguments=${JSON.stringify([args])}`;
          deleteTraceWorkflows(params).then(res => {
            selectedRows.forEach(row => {
              const affairId = row.affairId;
              try {
                closeOpenMultyWindow(affairId);
              } catch (e) {
              }
            });
            resetTableData();
          });
        }
      });
    }
  }
};
</script>
